home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-12-13 | 3.6 KB | 116 lines | [TEXT/ALFA] |
- ## -*-Tcl-*- (install)
- # ###################################################################
- # Alpha - new Tcl folder configuration
- #
- # FILE: "recentFiles.tcl"
- # created: 21/9/97 {9:14:38 pm}
- # last update: 13/12/97 {12:36:24 am}
- #
- # Reorganisation carried out by Vince Darley with much help from Tom
- # Fetherston, Johan Linde and suggestions from the Alpha-D mailing list.
- # Alpha is shareware; please register with the author using the register
- # button in the about box.
- #
- # original author probably Pete Keleher. Vince added a bunch of
- # code to work-around some Alpha-menu problems, and made it a
- # package.
- #
- # Version 0.2 builds the menu about a zillion times faster than
- # the original which built the menu once for every item at
- # startup! Also removed two unnecessary procs, since that stuff
- # can be done elsewhere automatically.
- # ###################################################################
- ##
-
- alpha::extension recentFilesMenu 0.2.3 {
- namespace eval recent {}
- ensureset recent::Files ""
- hook::register saveasHook recent::push
- hook::register openHook recent::push
- menu::buildProc recent recent::makeMenu
- menu::insert File submenu 2 recent
- lappend modifiedVars recent::Files
- } help {Adds a menu of recent files to the files menu}
-
- newPref variable numberOfRecentFiles 15
- ##
- # -------------------------------------------------------------------------
- #
- # "recent::push" --
- #
- # Works with files whose name contained '[' or ']' which didn't before.
- # Doesn't add any file which fails 'file exists' to the menu.
- # I also increased the number of files to 15. There should really
- # be a global flag to adjust for that.
- # -------------------------------------------------------------------------
- ##
- proc recent::push {name {name2 ""}} {
- if {$name2 != ""} { set name $name2 }
- global recent::Files numberOfRecentFiles
-
- regsub { <\w+>$} $name {} name
- if ![file exists $name] { return }
- regsub -all {\\([][])} $name {\1} name
- if {[info exists recent::Files] \
- && ([set ind [lsearch -regexp ${recent::Files} ":[quote::Regfind [file tail $name]]…?$"]] >= 0)} {
- set recent::Files [lreplace ${recent::Files} $ind $ind]
- lappend recent::Files $name
- return
- }
- lappend recent::Files $name
- if {[llength ${recent::Files}] > $numberOfRecentFiles} {
- set recent::Files [lrange ${recent::Files} 1 end]
- }
- recent::makeMenu
- }
-
- proc recent::makeMenu {} {
- global recent::Files
- set tails [map {file tail} ${recent::Files}]
- menu -m -c -n recent -p recent::menuProc \
- [concat [lsort -ignore $tails] [list "(-" "Reset List"]]
- set enable [expr [llength ${recent::Files}] ? 1 : 0]
- enableMenuItem File recent $enable
-
- }
-
- ##
- # -------------------------------------------------------------------------
- #
- # "recent::menuProc" --
- #
- # Works with menu items which contain '[', ']' and '…' which didn't work
- # before.
- # -------------------------------------------------------------------------
- ##
- proc recent::menuProc {menu name} {
- global recent::Files
-
- if {$name == "Reset List"} {
- set recent::Files {}
- menu -m -n recent -p recent::menuProc {}
- recent::makeMenu
- } else {
- if {[set ind [lsearch -regexp ${recent::Files} ":[quote::Regfind $name]…?$"]] >= 0} {
- edit [lindex ${recent::Files} $ind]
- } else {
- alpha::errorAlert "Couldn't find a file '$name'. Weird!"
- }
- }
- }
-
- proc recent::editFile {} {
- global recent::Files
-
- foreach f ${recent::Files} {
- lappend tails [file tail $f]
- }
-
- foreach res [listpick -l -p {File?} [lsort -ignore $tails]] {
- set ind [lsearch ${recent::Files} \*:$res]
- catch {edit [lindex ${recent::Files} $ind]}
- }
- }
-
-
-